//
//  ParkingView.m
//  WWXELuShang
//
//  Created by lanou on 15/12/22.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "ParkingView.h"
#import "TimeManage.h"

@implementation ParkingView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kBackGroundColor;
        
        [self addSubview:self.parkingButton];
        [self addSubview:self.timeTableView];
        self.timeTableView.delegate = target;
        self.timeTableView.dataSource = target;
        [self addSubview:self.markView];
        [self.markView addSubview:self.markButton];

    }
    return self;
}

- (UIView *)markView {
    if (!_markView) {
        _markView = [[UIView alloc] initWithFrame:CGRectMake(kWidth / 5 * 3, self.parkingButton.center.y, kWidth * 0.4- kWidth / 40, kWidth / 6)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _markView.frame.size.width - kWidth / 6, kWidth / 6)];
        label.userInteractionEnabled = YES;
        label.text = @"标记车位";
        label.font = [UIFont systemFontOfSize:kWidth / 22];
        [_markView addSubview:label];

    }
    return _markView;
}


- (UIButton *)markButton {
    if (!_markButton) {
        _markButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _markButton.frame = CGRectMake(self.markView.frame.size.width - kWidth / 6, 0, kWidth / 6, kWidth / 6);
        [self setmarkButtonImage];
    }
    return _markButton;
    
}

- (void)setmarkButtonImage {
    if ([TimeManage sharedTimeManage].isMarked) {
        [_markButton setImage:[[UIImage imageNamed:@"check_box_64px_1181750_easyicon.net"]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateNormal)];
    }else {
        [_markButton setImage:[[UIImage imageNamed:@"check_box_outline_blank_64px_1181751_easyicon.net"]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateNormal)];
    }
}


- (UITableView *)timeTableView {
    if (!_timeTableView) {
        _timeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kWidth / 10, kWidth, kHeight / 2)];
        _timeTableView.backgroundColor = [UIColor whiteColor];
        _timeTableView.bounces = NO;
    }
    return _timeTableView;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kWidth / 3, kWidth / 3, kWidth / 3)];

        _imageView.image = [UIImage imageNamed:@"parking"];
    }
    return _imageView;
}

- (UIButton *)parkingButton {
    if (!_parkingButton) {
        _parkingButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _parkingButton.frame = CGRectMake(kWidth / 5, self.timeTableView.frame.origin.y + self.timeTableView.frame.size.height + kWidth / 20, kWidth / 3, kWidth / 3);
        [_parkingButton setTitle:@"开始计时" forState:(UIControlStateNormal)];

        [_parkingButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_parkingButton setBackgroundImage:[UIImage imageNamed:@"Circle_Green_128px_566284_easyicon.net"] forState:(UIControlStateNormal)];
    }
    return _parkingButton;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
